from rest_framework.pagination import PageNumberPagination
from rest_framework import mixins
from rest_framework import viewsets

from apps.database.serializers import DateBaseSerializers
from apps.database.models import DateBase

# Create your views here.


class DateBasePagination(PageNumberPagination):
    """
    测试项目列表自定义分页
    """

    # 默认每页显示的个数
    page_size = 10
    # 可以动态改变每页显示的个数
    page_size_query_param = 'limit'
    # 页码参数
    page_query_param = 'page'
    # 最多能显示多少页
    max_page_size = 100


class DateBaseViewSet(mixins.ListModelMixin, mixins.CreateModelMixin, viewsets.GenericViewSet):

    queryset = DateBase.objects.all().order_by('-edit_time')
    serializer_class = DateBaseSerializers
    pagination_class = DateBasePagination
    search_fields = ('name', )
